package main;

import java.util.ArrayList;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;

import comparator.BDM;
import file.FileSD;

public class Main {
	private static int numReducesTask = 5;

	public static void main(String[] args) throws Exception {
		ArrayList<FileSD> listOfFiles = new ArrayList<FileSD>();
		Configuration conf = new Configuration();
		conf.set("numReduceTasks", String.valueOf(numReducesTask));
		String[] otherArgs = new GenericOptionsParser(conf, args)
				.getRemainingArgs();
		if (otherArgs.length != 3) {
			System.err.println("Usage: wordcount <in> <out>");
			System.exit(2);
		}
		Job job = new Job(conf, "Count Files");
		job.setJarByClass(BDM.class);
		job.setMapperClass(BDM.Map.class);
		//job.setPartitionerClass(BDM.Partition.class);
		job.setReducerClass(BDM.Reduce.class);
		job.setOutputKeyClass(Text.class);
		job.setOutputValueClass(FileSD.class);
		//job.setNumReduceTasks(numReducesTask);
		Path[] paths = {new Path(otherArgs[0]), new Path(otherArgs[1])};
		for (Path p : paths) {
	    	FileInputFormat.addInputPath(job, p);
		}
		FileInputFormat.setInputPaths(job, paths);
		FileOutputFormat.setOutputPath(job, new Path(otherArgs[2]));
		System.exit(job.waitForCompletion(true) ? 0 : 1);
	}

}
